package cn.itcast.service.cargo.impl;

import cn.itcast.dao.cargo.InvoiceDao;
import cn.itcast.dao.system.UserDao;
import cn.itcast.domain.cargo.CoInvoice;
import cn.itcast.domain.system.User;
import cn.itcast.service.cargo.InvoiceService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service(timeout = 1200000)
public class InvoiceServiceImpl implements InvoiceService {
    @Autowired
    private InvoiceDao invoiceDao;

    @Override
    public PageInfo<CoInvoice> findByPage(int pageNum, int pageSize) {
        // 开启分页支持，紧随其后的第一条查询自动进行分页
        PageHelper.startPage(pageNum, pageSize);
        // 调用dao查询
        List<CoInvoice> list = invoiceDao.findAll();
        // 封装分页参数并返回
        PageInfo<CoInvoice> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * 删除发票
     * @param id
     * @return
     */
    @Override
    public boolean deteleById(String id) {

        //根据id查询发票状态
        CoInvoice all = invoiceDao.findAllById(id);
        if (all.getStatus() == 0) {
            int num = invoiceDao.deleteById(id);
            if (num > 0)
                return true;
        }
        return false;
    }
}
